﻿using System;
using System.Windows.Forms;
using mfe.bll;

namespace mfe_proj
{
    public partial class MainForm : Form
    {
        Forms.ContentViewer conForm = null;
        Forms.NavigationForm navForm = null;
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            MinimumSize = new System.Drawing.Size(800, 450);

            navForm = new mfe_proj.Forms.NavigationForm();
            navForm.DoubleClicked += new mfe_proj.Forms.NavigationFormEventHandler(navForm_DoubleClicked);
            navForm.LoadData();
            navForm.DockablePanel.Parent = splitContainer1.Panel1;
        }

        void navForm_DoubleClicked(object sender, mfe_proj.Forms.NavigationFormEventArgs e)
        {
            if (conForm == null)
            {
                conForm = new mfe_proj.Forms.ContentViewer();
                conForm.DockablePanel.Parent = splitContainer1.Panel2;
            }
            conForm.LoadItem(e._ItemGuidID);
        }

        void t_DoubleClicked(object sender, TestFormEventArgs e)
        {
            if (conForm == null)
            {
                conForm = new mfe_proj.Forms.ContentViewer();
                conForm.DockablePanel.Parent = splitContainer1.Panel2;
            }
            conForm.LoadItem(e._ItemGuidID);
        }

        private void btnAuthors_Click(object sender, EventArgs e)
        {
            //Forms.AuthorForm form = new mfe_proj.Forms.AuthorForm();
            //form.ShowDialog();
            Forms.ItemForm form = new mfe_proj.Forms.ItemForm();
            form.ShowDialog();
        }

        private void testFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            Forms.ItemForm itemForm = new mfe_proj.Forms.ItemForm();
            itemForm.ShowDialog();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (conForm != null)
                conForm.Print();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            Forms.ItemForm itemForm = new mfe_proj.Forms.ItemForm();
            itemForm.ItemGuidID = navForm.SelectedGuidID;
            itemForm.ShowDialog();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Item.Delete(navForm.SelectedGuidID);
                navForm.Refresh();
            }
        }
    }
}
